package com.hehui.partimejob.view;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.hehui.partimejob.R;

public class NavView {

    private RelativeLayout nav;

    public RelativeLayout createNavForActivity(Window window, Activity activity) {
        ViewGroup viewById = window.getDecorView().findViewById(android.R.id.content);
        ViewGroup root = (ViewGroup) viewById.getChildAt(0);
        nav = (RelativeLayout) LayoutInflater.from(activity).inflate(R.layout.base_nav, root, false);
        root.addView(nav, 0);
        nav.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
        return nav;
    }
    public RelativeLayout createNavForFragment(ViewGroup view,Fragment fragment) {

        nav = (RelativeLayout) LayoutInflater.from(view.getContext()).inflate(R.layout.base_nav, view, false);
        view.addView(nav, 0);
        nav.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fragment.getActivity().finish();
            }
        });
        return nav;
    }


    public RelativeLayout getNavRightView() {
        return nav.findViewById(R.id.right);
    }

    public View getBack(){
        return nav.findViewById(R.id.back);
    }
    public NavView setTitle(String str) {
        TextView textView = nav.findViewById(R.id.title);
        textView.setText(str);
        return  this;
    }
    public NavView setTitleColor(int color) {
        TextView textView = nav.findViewById(R.id.title);
        textView.setTextColor(color);
        return  this;
    }

    public NavView setTitle(int id) {
        TextView textView = nav.findViewById(R.id.title);
        textView.setText(id);
        return this;
    }

    public NavView isShowBack(boolean flag){
        View viewById = nav.findViewById(R.id.back);
        viewById.setVisibility(flag?View.VISIBLE:View.INVISIBLE);
        return this;
    }

    public void hide() {
        nav.setVisibility(View.GONE);
    }

    public RelativeLayout getNav() {
        return nav;
    }

    public void setNav(RelativeLayout nav) {
        this.nav = nav;
    }
}
